package ProjectTeam39.GUITest;

import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.BorderLayout;

import javax.swing.ButtonGroup;
import javax.swing.SwingConstants;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.Component;
import javax.swing.JSplitPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import ProjectTeam39.Domains.*;
public class NurseFrame extends JFrame {
	private NurseFrame nframe = this;
	private JTextField txtFullName;
	private JTextField txtPhone;
	private JTextField txtAddress;
	private JTextField txtUsername;
	private JTextField txtPassword;
	private UserList ul;
	Nurse joy;
	short buttonPressed= -1;
	JLabel results;
	
	public NurseFrame(final UserList ul) {
		joy = new Nurse("title", "title", "title", new Long("7707787799"), "title", null, ul);
		this.ul = ul;
		ButtonGroup radios = new ButtonGroup();
		JPanel panel = new JPanel();
		getContentPane().add(panel, BorderLayout.NORTH);
		
		JPanel panel_4 = new JPanel();
		panel.add(panel_4);
		
		JSplitPane splitPane_2 = new JSplitPane();
		panel_4.add(splitPane_2);
		
		
		JPanel panel_1 = new JPanel();
		getContentPane().add(panel_1, BorderLayout.SOUTH);
		
		JButton btnLogout = new JButton("Logout");
		btnLogout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				LoginFrame lframe = new LoginFrame(ul);
				lframe.setBounds(100, 100, 450, 300);
				lframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				nframe.setVisible(false);
				lframe.setVisible(true);
			}
		});
		panel_1.add(btnLogout);
		
		JPanel panel_5 = new JPanel();
		getContentPane().add(panel_5, BorderLayout.CENTER);
		panel_5.setLayout(new BorderLayout(0, 0));
		
		JSplitPane splitPane = new JSplitPane();
		panel_5.add(splitPane, BorderLayout.NORTH);
		
		JSplitPane splitPane_1 = new JSplitPane();
		splitPane.setRightComponent(splitPane_1);
		
		txtPhone = new JTextField();
		txtPhone.setText("Phone #");
		splitPane_1.setLeftComponent(txtPhone);
		txtPhone.setColumns(10);
		
		txtAddress = new JTextField();
		txtAddress.setText("Address");
		splitPane_1.setRightComponent(txtAddress);
		txtAddress.setColumns(10);
		
		txtFullName = new JTextField();
		txtFullName.setText("Full Name");
		splitPane.setLeftComponent(txtFullName);
		txtFullName.setColumns(10);
		
		JPanel panel_2 = new JPanel();
		panel_5.add(panel_2, BorderLayout.CENTER);
		
		txtUsername = new JTextField();
		txtUsername.setText("Username");
		panel_2.add(txtUsername);
		txtUsername.setColumns(10);
		
		txtPassword = new JTextField();
		txtPassword.setText("Password");
		panel_2.add(txtPassword);
		txtPassword.setColumns(10);
		
		JPanel panel_3 = new JPanel();
		panel_5.add(panel_3, BorderLayout.SOUTH);
		
		final JLabel results = new JLabel("");
		panel_3.add(results);
		this.results = results;
		
		final JRadioButton rdbtnViewPatient = new JRadioButton("View Patient");
		rdbtnViewPatient.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				buttonPressed = 0;
				txtFullName.setEnabled(true);
				txtPhone.setEnabled(false);
				txtAddress.setEnabled(false);
				txtUsername.setEnabled(false);
				txtPassword.setEnabled(false);
			}
		});
		splitPane_2.setLeftComponent(rdbtnViewPatient);
		radios.add(rdbtnViewPatient);
		
		JRadioButton rdbtnCreatePatient = new JRadioButton("Create Patient");
		rdbtnCreatePatient.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				buttonPressed = 1;
				txtFullName.setEnabled(true);
				txtPhone.setEnabled(true);
				txtAddress.setEnabled(true);
				txtUsername.setEnabled(true);
				txtPassword.setEnabled(true);
			}
		});
		splitPane_2.setRightComponent(rdbtnCreatePatient);
		radios.add(rdbtnCreatePatient);
		
		JSplitPane splitPane_3 = new JSplitPane();
		panel_4.add(splitPane_3);
		
		JRadioButton rdbtnRemovePatient = new JRadioButton("Remove Patient");
		rdbtnRemovePatient.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				buttonPressed = 2;
				txtFullName.setEnabled(true);
				txtPhone.setEnabled(false);
				txtAddress.setEnabled(false);
				txtUsername.setEnabled(false);
				txtPassword.setEnabled(false);
			}
		});
		splitPane_3.setLeftComponent(rdbtnRemovePatient);
		radios.add(rdbtnRemovePatient);
		
		JRadioButton rdbtnCreateTreatmentRecord = new JRadioButton("Create Treatment Record");
		rdbtnCreateTreatmentRecord.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				buttonPressed = 3;
				txtPhone.setEnabled(false);
				txtAddress.setEnabled(false);
				txtUsername.setEnabled(false);
				txtPassword.setEnabled(false);
				txtFullName.setEnabled(false);
			}
		});
		radios.add(rdbtnCreateTreatmentRecord);
		splitPane_3.setRightComponent(rdbtnCreateTreatmentRecord);
		
		JButton btnSubmit = new JButton("Submit");
		btnSubmit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				switch(buttonPressed){
				case -1: results.setText("Please choose an option"); break;
				case 0: viewPatient(); break;
				case 1: createPatient(); break;
				case 2: removePatient(); break;
				case 3: createTreatmentRecord(); break;
				}
			}
		});
		panel_1.add(btnSubmit);
	}

	public void createPatient(){
		results.setText("I made my first patient!");
	}
	
	public void viewPatient(){
		String name = txtFullName.getText();
		Patient p = joy.viewPatient(name);
		results.setText("Found him");
	}
	
	public void removePatient(){
		String name = txtFullName.getText();
		boolean completed = joy.removePatient(name);
		if(!completed){
			results.setText("Patient not in database");
		}
		else
			results.setText("Patient removed successfully");
	}
	
	public void createTreatmentRecord(){
		createRecordFrame rframe = new createRecordFrame(this);
		this.setVisible(false);
		rframe.setBounds(100, 100, 450, 300);
		rframe.setVisible(true);
		rframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}
